local love = require 'love'
local fontHandler = require('assets-handler.font-handler')

local setColor = love.graphics.setColor
local drawRectangle = love.graphics.rectangle
local polygon = love.graphics.polygon
local printg = love.graphics.print
local setLineWidth = love.graphics.setLineWidth
local line = love.graphics.line

local width = Width
local height = Height
local padding = Padding

local guide = {
    step = 1,
    stage = 1,
    fontSize = 20,
    fontHeight = 0,
    textBackgroundColor = {0.004, 0.345, 0.549, 0.9},
    textColor = {1, 1, 1, 1},
    areaColor = {0.004, 0.298, 0.471, 0.5},
    triangleColor = {0, 0, 0, 1}
}

local midLine = {
    x = 0,
    color = {1, 1, 1, 0.8}
}

local guideNewPlayer = {
    text = "我是新手",
    fontWidth = 0,
    buttonX = 0,
    buttonY = 0,
    buttonWidth = 0,
    buttonHeight = 0,
    textX = 0,
    textY = 0,
    buttonColor = {},
    buttonColorHovered = {0.102, 0.545, 0.808, 1},
    buttonColorNormal = {0.004, 0.443, 0.706, 1},
    areaColor = {},
    areaColorHovered = {0.502, 0.749, 0.890, 0.5},
    areaColorNormal = {0.302, 0.647, 0.847, 0.5}
}

local guideSkip = {
    text= "跳过指导",
    fontWidth = 0,
    buttonX = 0,
    buttonY = 0,
    buttonWidth = 0,
    buttonHeight = 0,
    textX = 0,
    textY = 0,
    buttonColor = {},
    buttonColorHovered = {0.584, 0.761, 0.204, 1},
    buttonColorNormal = {0.482, 0.659, 0.106, 1},
    areaColor = {},
    areaColorHovered = {0.769, 0.867, 0.561, 0.5},
    areaColorNormal = {0.722, 0.839, 0.471, 0.5}
}

local guideHandCards = {
    text = "框选手牌",
    fontWidth = 0,
    rectY = 0,
    rectHeight = 0,
    textX = 0,
    textY = 0,
    areaX = 0,
    areaY = 0,
    areaWidth = 0,
    areaHeight = 0,
    triangleX = 0,
    triangleY1 = 0,
    triangleY2 = 0,
    triangleWidth = 0
}

local guidePlay = {
    text = "选牌后点击下方红色按钮出牌",
    fontWidth = 0,
    rectY = 0,
    rectHeight = 0,
    textX = 0,
    textY = 0,
    areaX = 0,
    areaY = 0,
    areaWidth = 0,
    areaHeight = 0,
    triangleX = 0,
    triangleY1 = 0,
    triangleY2 = 0,
    triangleWidth = 0
}

local guideDiscard = {
    text = "选牌后也可以直接弃牌",
    fontWidth = 0,
    rectY = 0,
    rectHeight = 0,
    textX = 0,
    textY = 0,
    areaX = 0,
    areaY = 0,
    areaWidth = 0,
    areaHeight = 0,
    triangleX = 0,
    triangleY1 = 0,
    triangleY2 = 0,
    triangleWidth = 0
}

local guideReorder = {
    text = "按花色排序或按点数排序",
    fontWidth = 0,
    rectY = 0,
    rectHeight = 0,
    textX = 0,
    textY = 0,
    areaX = 0,
    areaY = 0,
    areaWidth = 0,
    areaHeight = 0,
    triangleX = 0,
    triangleY1 = 0,
    triangleY2 = 0,
    triangleWidth = 0
}

local guideDeck = {
    text = "点击右下角按钮显示牌库",
    fontWidth = 0,
    rectY = 0,
    rectHeight = 0,
    textX = 0,
    textY = 0,
    areaX = 0,
    areaY = 0,
    areaWidth = 0,
    areaHeight = 0,
    triangleX = 0,
    triangleY1 = 0,
    triangleY2 = 0,
    triangleWidth = 0
}

local guideInfoBar = {
    text = "右侧信息栏↑/↓键查看历史",
    fontWidth = 0,
    rectY = 0,
    rectHeight = 0,
    textX = 0,
    textY = 0,
    areaX = 0,
    areaY = 0,
    areaWidth = 0,
    areaHeight = 0,
    triangleX = 0,
    triangleY1 = 0,
    triangleY2 = 0,
    triangleWidth = 0
}

local guideGift = {
    text = "天赋栏",
    fontWidth = 0,
    rectY = 0,
    rectHeight = 0,
    textX = 0,
    textY = 0,
    areaX = 0,
    areaY = 0,
    areaWidth = 0,
    areaHeight = 0,
    triangleX = 0,
    triangleY1 = 0,
    triangleY2 = 0,
    triangleWidth = 0
}

local guideRestart = {
    text = "重开游戏",
    fontWidth = 0,
    rectY = 0,
    rectHeight = 0,
    textX = 0,
    textY = 0,
    areaX = 0,
    areaY = 0,
    areaWidth = 0,
    areaHeight = 0,
    triangleX = 0,
    triangleY1 = 0,
    triangleY2 = 0,
    triangleWidth = 0
}

local guideLifeOpponent = {
    text = "对手生命值",
    fontWidth = 0,
    rectY = 0,
    rectHeight = 0,
    textX = 0,
    textY = 0,
    areaX = 0,
    areaY = 0,
    areaWidth = 0,
    areaHeight = 0,
    triangleX = 0,
    triangleY1 = 0,
    triangleY2 = 0,
    triangleWidth = 0
}

local guideMore = {
    text = "获取更多帮助",
    fontWidth = 0,
    rectY = 0,
    rectHeight = 0,
    textX = 0,
    textY = 0,
    areaX = 0,
    areaY = 0,
    areaWidth = 0,
    areaHeight = 0,
    triangleX = 0,
    triangleY1 = 0,
    triangleY2 = 0,
    triangleWidth = 0
}

local guideEnd = {
    text = "击败怪物，努力获取更高分!",
    fontWidth = 0,
    rectY = 0,
    rectHeight = 0,
    textX = 0,
    textY = 0
}

local guideFinished = false

local function init()
    midLine.x = width / 2

    fontHandler.setFont(guide.fontSize)
    guide.fontHeight = fontHandler.getFontHeight()

    guideNewPlayer.fontWidth = fontHandler.getFontWidth(guideNewPlayer.text)
    guideNewPlayer.textX = width / 4 - guideNewPlayer.fontWidth / 2
    guideNewPlayer.textY = height * (1 - 0.618) - guide.fontHeight / 2
    guideNewPlayer.buttonWidth = guideNewPlayer.fontWidth + padding * 2
    guideNewPlayer.buttonHeight = guide.fontHeight + padding
    guideNewPlayer.buttonX = width / 4 - guideNewPlayer.buttonWidth / 2
    guideNewPlayer.buttonY = height * (1 - 0.618) - guideNewPlayer.buttonHeight / 2 - guide.fontHeight / 6
    guideNewPlayer.buttonColor = guideNewPlayer.buttonColorNormal
    guideNewPlayer.areaColor = guideNewPlayer.areaColorNormal

    guideSkip.fontWidth = fontHandler.getFontWidth(guideSkip.text)
    guideSkip.textX = width / 4 - guideSkip.fontWidth / 2 + width / 2
    guideSkip.textY = height * (1 - 0.618) - guide.fontHeight / 2
    guideSkip.buttonWidth = guideSkip.fontWidth + padding * 2
    guideSkip.buttonHeight = guide.fontHeight + padding
    guideSkip.buttonX = width / 4 - guideSkip.buttonWidth / 2 + width / 2
    guideSkip.buttonY = height * (1 - 0.618) - guideSkip.buttonHeight / 2 - guide.fontHeight / 6
    guideSkip.buttonColor = guideSkip.buttonColorNormal
    guideSkip.areaColor = guideSkip.areaColorNormal

    -- 手牌
    local handCardsHeight = height / 6
    local handCardsY = height - padding - handCardsHeight - height / 20 * 2
    local handCardsSelectedY = handCardsY - height / 20

    guideHandCards.fontWidth = fontHandler.getFontWidth(guideHandCards.text)
    guideHandCards.rectY = handCardsSelectedY - guide.fontHeight - guide.fontHeight / 3
    guideHandCards.rectHeight = guide.fontHeight + guide.fontHeight / 3
    guideHandCards.textX = (width - guideHandCards.fontWidth) / 2
    guideHandCards.textY = handCardsSelectedY - guide.fontHeight

    guideHandCards.areaX = padding
    guideHandCards.areaY = handCardsY
    guideHandCards.areaWidth = width - padding * 2
    guideHandCards.areaHeight = handCardsHeight

    guideHandCards.triangleX = width / 2
    guideHandCards.triangleY1 = guideHandCards.areaY
    guideHandCards.triangleY2 = guideHandCards.rectY + guideHandCards.rectHeight
    guideHandCards.triangleWidth = width / 15

    -- 出牌
    local playCircleRadius = height / 20

    guidePlay.areaX = width / 2 - playCircleRadius
    guidePlay.areaY = height - padding * 3 - playCircleRadius * 2
    guidePlay.areaWidth = playCircleRadius * 2
    guidePlay.areaHeight = playCircleRadius * 2

    guidePlay.fontWidth = fontHandler.getFontWidth(guidePlay.text)
    guidePlay.rectHeight = guide.fontHeight + guide.fontHeight / 3
    guidePlay.rectY = guidePlay.areaY - guidePlay.rectHeight - padding
    guidePlay.textX = (width - guidePlay.fontWidth) / 2
    guidePlay.textY = guidePlay.rectY + guide.fontHeight / 3

    guidePlay.triangleX = width / 2
    guidePlay.triangleY1 = guidePlay.areaY
    guidePlay.triangleY2 = guidePlay.rectY + guidePlay.rectHeight
    guidePlay.triangleWidth = width / 15

    -- 弃牌
    local DiscardButtonWidth = height / 20
    local DiscardButtonHeight = DiscardButtonWidth

    guideDiscard.areaX = width / 2 + DiscardButtonWidth
    guideDiscard.areaY = height - padding * 2 - DiscardButtonHeight
    guideDiscard.areaWidth = DiscardButtonWidth
    guideDiscard.areaHeight = DiscardButtonHeight

    guideDiscard.fontWidth = fontHandler.getFontWidth(guideDiscard.text)
    guideDiscard.rectHeight = guide.fontHeight + guide.fontHeight / 3
    guideDiscard.rectY = guideDiscard.areaY - guideDiscard.rectHeight - padding
    guideDiscard.textX = (width - guideDiscard.fontWidth) / 2
    guideDiscard.textY = guideDiscard.rectY + guide.fontHeight / 3

    guideDiscard.triangleX = guideDiscard.areaX + guideDiscard.areaWidth / 2
    guideDiscard.triangleY1 = guideDiscard.areaY
    guideDiscard.triangleY2 = guideDiscard.rectY + guideDiscard.rectHeight
    guideDiscard.triangleWidth = width / 15

    -- 换花色
    guideReorder.areaX = width / 2 - playCircleRadius - DiscardButtonWidth
    guideReorder.areaY = height - padding * 2 - DiscardButtonHeight
    guideReorder.areaWidth = DiscardButtonWidth
    guideReorder.areaHeight = DiscardButtonHeight

    guideReorder.fontWidth = fontHandler.getFontWidth(guideReorder.text)
    guideReorder.rectHeight = guide.fontHeight + guide.fontHeight / 3
    guideReorder.rectY = guideReorder.areaY - guideReorder.rectHeight - padding
    guideReorder.textX = (width - guideReorder.fontWidth) / 2
    guideReorder.textY = guideReorder.rectY + guide.fontHeight / 3

    guideReorder.triangleX = guideReorder.areaX + guideReorder.areaWidth / 2
    guideReorder.triangleY1 = guideReorder.areaY
    guideReorder.triangleY2 = guideReorder.rectY + guideReorder.rectHeight
    guideReorder.triangleWidth = width / 15

    -- 牌库
    local deckTriangleWidth = width / 10
    local deckTriangleHeight = height / 12

    guideDeck.areaWidth = deckTriangleWidth
    guideDeck.areaHeight = deckTriangleHeight
    guideDeck.areaX = width - deckTriangleWidth
    guideDeck.areaY = height - deckTriangleHeight

    guideDeck.fontWidth = fontHandler.getFontWidth(guideDeck.text)
    guideDeck.rectHeight = guide.fontHeight + guide.fontHeight / 3
    guideDeck.rectY = handCardsY + handCardsHeight - guideDeck.rectHeight
    guideDeck.textX = (width - guideDeck.fontWidth) / 2
    guideDeck.textY = guideDeck.rectY + guide.fontHeight / 3

    guideDeck.triangleX = guideDeck.areaX + guideDeck.areaWidth / 2
    guideDeck.triangleY1 = guideDeck.areaY
    guideDeck.triangleY2 = guideDeck.rectY + guideDeck.rectHeight
    guideDeck.triangleWidth = width / 15

    -- 信息栏
    local infoBarFontHeight = 25  -- 字体为 14 的行高加4

    guideInfoBar.areaWidth = width
    guideInfoBar.areaHeight = infoBarFontHeight * 4
    guideInfoBar.areaX = 0
    guideInfoBar.areaY = handCardsY - guideInfoBar.areaHeight

    guideInfoBar.fontWidth = fontHandler.getFontWidth(guideInfoBar.text)
    guideInfoBar.rectHeight = guide.fontHeight + guide.fontHeight / 3
    guideInfoBar.rectY = guideInfoBar.areaY - guideInfoBar.rectHeight - padding
    guideInfoBar.textX = (width - guideInfoBar.fontWidth) / 2
    guideInfoBar.textY = guideInfoBar.rectY + guide.fontHeight / 3

    guideInfoBar.triangleX = guideInfoBar.areaX + guideInfoBar.areaWidth / 2
    guideInfoBar.triangleY1 = guideInfoBar.areaY
    guideInfoBar.triangleY2 = guideInfoBar.rectY + guideInfoBar.rectHeight
    guideInfoBar.triangleWidth = width / 15

    -- 天赋栏
    local boxWidth = width / 13
    local boxHeight = (height - padding * 2) * 0.372
    local boxX = width - padding * 2 - boxWidth
    local boxY = (height - boxHeight) / 4

    guideGift.areaWidth = boxWidth
    guideGift.areaHeight = boxHeight
    guideGift.areaX = boxX
    guideGift.areaY = boxY

    guideGift.fontWidth = fontHandler.getFontWidth(guideGift.text)
    guideGift.rectHeight = guide.fontHeight + guide.fontHeight / 3
    guideGift.rectY = guideGift.areaY - guideGift.rectHeight - padding
    guideGift.textX = (width - guideGift.fontWidth) / 2
    guideGift.textY = guideGift.rectY + guide.fontHeight / 3

    guideGift.triangleX = guideGift.areaX + guideGift.areaWidth / 2
    guideGift.triangleY1 = guideGift.areaY
    guideGift.triangleY2 = guideGift.rectY + guideGift.rectHeight
    guideGift.triangleWidth = width / 15

    -- 重开
    local restartButtonWidth = 25

    guideRestart.areaX = width - restartButtonWidth - padding
    guideRestart.areaY = padding
    guideRestart.areaWidth = restartButtonWidth
    guideRestart.areaHeight = restartButtonWidth

    guideRestart.fontWidth = fontHandler.getFontWidth(guideRestart.text)
    guideRestart.rectHeight = guide.fontHeight + guide.fontHeight / 3
    guideRestart.rectY = guideRestart.areaY + guideRestart.rectHeight + padding
    guideRestart.textX = (width - guideRestart.fontWidth) / 2
    guideRestart.textY = guideRestart.rectY + guide.fontHeight / 3

    guideRestart.triangleX = guideRestart.areaX + guideRestart.areaWidth / 2
    guideRestart.triangleY1 = guideRestart.areaY + guideRestart.areaHeight
    guideRestart.triangleY2 = guideRestart.rectY
    guideRestart.triangleWidth = width / 15

    -- 对手生命值
    local instructionsCircleRadius = 10
    local healthBarX = instructionsCircleRadius * 2 + padding * 2
    local healthBarWidth = width - padding * 4 - instructionsCircleRadius * 2 - restartButtonWidth
    local healthBarHeight = height / 30

    guideLifeOpponent.areaX = healthBarX
    guideLifeOpponent.areaY = padding
    guideLifeOpponent.areaWidth = healthBarWidth
    guideLifeOpponent.areaHeight = healthBarHeight

    guideLifeOpponent.fontWidth = fontHandler.getFontWidth(guideLifeOpponent.text)
    guideLifeOpponent.rectHeight = guide.fontHeight + guide.fontHeight / 3
    guideLifeOpponent.rectY = guideLifeOpponent.areaY + guideLifeOpponent.rectHeight + padding
    guideLifeOpponent.textX = (width - guideLifeOpponent.fontWidth) / 2
    guideLifeOpponent.textY = guideLifeOpponent.rectY + guide.fontHeight / 3

    guideLifeOpponent.triangleX = guideLifeOpponent.areaX + guideLifeOpponent.areaWidth / 2
    guideLifeOpponent.triangleY1 = guideLifeOpponent.areaY + guideLifeOpponent.areaHeight
    guideLifeOpponent.triangleY2 = guideLifeOpponent.rectY
    guideLifeOpponent.triangleWidth = width / 15

    -- 更多帮助
    guideMore.areaX = padding
    guideMore.areaY = padding
    guideMore.areaWidth = instructionsCircleRadius * 2
    guideMore.areaHeight = instructionsCircleRadius * 2

    guideMore.fontWidth = fontHandler.getFontWidth(guideMore.text)
    guideMore.rectHeight = guide.fontHeight + guide.fontHeight / 3
    guideMore.rectY = guideMore.areaY + guideMore.rectHeight + padding
    guideMore.textX = (width - guideMore.fontWidth) / 2
    guideMore.textY = guideMore.rectY + guide.fontHeight / 3

    guideMore.triangleX = guideMore.areaX + guideMore.areaWidth / 2
    guideMore.triangleY1 = guideMore.areaY + guideMore.areaHeight
    guideMore.triangleY2 = guideMore.rectY
    guideMore.triangleWidth = width / 15

    -- 努力获取更高分
    guideEnd.fontWidth = fontHandler.getFontWidth(guideEnd.text)
    guideEnd.rectHeight = guide.fontHeight + guide.fontHeight / 3
    guideEnd.rectY = height * (1 - 0.618)
    guideEnd.textX = (width - guideEnd.fontWidth) / 2
    guideEnd.textY = guideEnd.rectY + guide.fontHeight / 3
end

local function drawGuide()
    fontHandler.setFont(guide.fontSize)

    if guide.step == 1 then
        -- 是否进入指南
        setColor(midLine.color)
        setLineWidth(2)
        line(midLine.x, 0, midLine.x, height)
        setColor(guideNewPlayer.areaColor)
        drawRectangle("fill", 0, 0, width / 2, height)
        setColor(guideSkip.areaColor)
        drawRectangle("fill", midLine.x, 0, width / 2, height)
        setColor(guideNewPlayer.buttonColor)
        drawRectangle("fill", guideNewPlayer.buttonX, guideNewPlayer.buttonY, guideNewPlayer.buttonWidth, guideNewPlayer.buttonHeight, 10, 10)
        setColor(guideSkip.buttonColor)
        drawRectangle("fill", guideSkip.buttonX, guideSkip.buttonY, guideSkip.buttonWidth, guideSkip.buttonHeight, 10, 10)
        setColor(guide.textColor)
        drawRectangle("line", guideNewPlayer.buttonX, guideNewPlayer.buttonY, guideNewPlayer.buttonWidth, guideNewPlayer.buttonHeight, 10, 10)
        drawRectangle("line", guideSkip.buttonX, guideSkip.buttonY, guideSkip.buttonWidth, guideSkip.buttonHeight, 10, 10)
        printg(guideNewPlayer.text, guideNewPlayer.textX, guideNewPlayer.textY)
        printg(guideSkip.text, guideSkip.textX, guideSkip.textY)
    elseif guide.step == 2 then
        -- 手牌区
        setColor(guide.textBackgroundColor)
        drawRectangle("fill", 0, guideHandCards.rectY, width, guideHandCards.rectHeight)
        setColor(guide.textColor)
        printg(guideHandCards.text, guideHandCards.textX, guideHandCards.textY)
        setColor(guide.areaColor)
        drawRectangle("fill", guideHandCards.areaX, guideHandCards.areaY, guideHandCards.areaWidth, guideHandCards.areaHeight)
        setColor(guide.triangleColor)
        polygon("fill",
            guideHandCards.triangleX, guideHandCards.triangleY1,
            guideHandCards.triangleX - guideHandCards.triangleWidth / 2, guideHandCards.triangleY2,
            guideHandCards.triangleX + guideHandCards.triangleWidth / 2, guideHandCards.triangleY2
        )
        setLineWidth(3)
        setColor(guide.triangleColor)
        drawRectangle("line", 0, guideHandCards.rectY, width, guideHandCards.rectHeight)
        drawRectangle("line", guideHandCards.areaX, guideHandCards.areaY, guideHandCards.areaWidth, guideHandCards.areaHeight)
    elseif guide.step == 3 then
        -- 出牌按钮
        setColor(guide.textBackgroundColor)
        drawRectangle("fill", 0, guidePlay.rectY, width, guidePlay.rectHeight)
        setColor(guide.textColor)
        printg(guidePlay.text, guidePlay.textX, guidePlay.textY)
        setColor(guide.areaColor)
        drawRectangle("fill", guidePlay.areaX, guidePlay.areaY, guidePlay.areaWidth, guidePlay.areaHeight)
        setColor(guide.triangleColor)
        polygon("fill",
            guidePlay.triangleX, guidePlay.triangleY1,
            guidePlay.triangleX - guidePlay.triangleWidth / 2, guidePlay.triangleY2,
            guidePlay.triangleX + guidePlay.triangleWidth / 2, guidePlay.triangleY2
        )
        setLineWidth(3)
        setColor(guide.triangleColor)
        drawRectangle("line", 0, guidePlay.rectY, width, guidePlay.rectHeight)
        drawRectangle("line", guidePlay.areaX, guidePlay.areaY, guidePlay.areaWidth, guidePlay.areaHeight)
    elseif guide.step == 4 then
        -- 弃牌按钮
        setColor(guide.textBackgroundColor)
        drawRectangle("fill", 0, guideDiscard.rectY, width, guideDiscard.rectHeight)
        setColor(guide.textColor)
        printg(guideDiscard.text, guideDiscard.textX, guideDiscard.textY)
        setColor(guide.areaColor)
        drawRectangle("fill", guideDiscard.areaX, guideDiscard.areaY, guideDiscard.areaWidth, guideDiscard.areaHeight)
        setColor(guide.triangleColor)
        polygon("fill",
            guideDiscard.triangleX, guideDiscard.triangleY1,
            guideDiscard.triangleX - guideDiscard.triangleWidth / 2, guideDiscard.triangleY2,
            guideDiscard.triangleX + guideDiscard.triangleWidth / 2, guideDiscard.triangleY2
        )
        setLineWidth(3)
        setColor(guide.triangleColor)
        drawRectangle("line", 0, guideDiscard.rectY, width, guideDiscard.rectHeight)
        drawRectangle("line", guideDiscard.areaX, guideDiscard.areaY, guideDiscard.areaWidth, guideDiscard.areaHeight)
    elseif guide.step == 5 then
        -- 换花色
        setColor(guide.textBackgroundColor)
        drawRectangle("fill", 0, guideReorder.rectY, width, guideReorder.rectHeight)
        setColor(guide.textColor)
        printg(guideReorder.text, guideReorder.textX, guideReorder.textY)
        setColor(guide.areaColor)
        drawRectangle("fill", guideReorder.areaX, guideReorder.areaY, guideReorder.areaWidth, guideReorder.areaHeight)
        setColor(guide.triangleColor)
        polygon("fill",
            guideReorder.triangleX, guideReorder.triangleY1,
            guideReorder.triangleX - guideReorder.triangleWidth / 2, guideReorder.triangleY2,
            guideReorder.triangleX + guideReorder.triangleWidth / 2, guideReorder.triangleY2
        )
        setLineWidth(3)
        setColor(guide.triangleColor)
        drawRectangle("line", 0, guideReorder.rectY, width, guideReorder.rectHeight)
        drawRectangle("line", guideReorder.areaX, guideReorder.areaY, guideReorder.areaWidth, guideReorder.areaHeight)
    elseif guide.step == 6 then
        -- 牌库区
        setColor(guide.textBackgroundColor)
        drawRectangle("fill", 0, guideDeck.rectY, width, guideDeck.rectHeight)
        setColor(guide.textColor)
        printg(guideDeck.text, guideDeck.textX, guideDeck.textY)
        setColor(guide.areaColor)
        drawRectangle("fill", guideDeck.areaX, guideDeck.areaY, guideDeck.areaWidth, guideDeck.areaHeight)
        setColor(guide.triangleColor)
        polygon("fill",
            guideDeck.triangleX, guideDeck.triangleY1,
            guideDeck.triangleX - guideDeck.triangleWidth / 2, guideDeck.triangleY2,
            guideDeck.triangleX + guideDeck.triangleWidth / 2, guideDeck.triangleY2
        )
        setLineWidth(3)
        setColor(guide.triangleColor)
        drawRectangle("line", 0, guideDeck.rectY, width, guideDeck.rectHeight)
        drawRectangle("line", guideDeck.areaX, guideDeck.areaY, guideDeck.areaWidth, guideDeck.areaHeight)
    elseif guide.step == 7 then
        -- 信息栏
        setColor(guide.textBackgroundColor)
        drawRectangle("fill", 0, guideInfoBar.rectY, width, guideInfoBar.rectHeight)
        setColor(guide.textColor)
        printg(guideInfoBar.text, guideInfoBar.textX, guideInfoBar.textY)
        setColor(guide.areaColor)
        drawRectangle("fill", guideInfoBar.areaX, guideInfoBar.areaY, guideInfoBar.areaWidth, guideInfoBar.areaHeight)
        setColor(guide.triangleColor)
        polygon("fill",
            guideInfoBar.triangleX, guideInfoBar.triangleY1,
            guideInfoBar.triangleX - guideInfoBar.triangleWidth / 2, guideInfoBar.triangleY2,
            guideInfoBar.triangleX + guideInfoBar.triangleWidth / 2, guideInfoBar.triangleY2
        )
        setLineWidth(3)
        setColor(guide.triangleColor)
        drawRectangle("line", 0, guideInfoBar.rectY, width, guideInfoBar.rectHeight)
        drawRectangle("line", guideInfoBar.areaX, guideInfoBar.areaY, guideInfoBar.areaWidth, guideInfoBar.areaHeight)
    elseif guide.step == 8 then
        -- 重开
        setColor(guide.textBackgroundColor)
        drawRectangle("fill", 0, guideRestart.rectY, width, guideRestart.rectHeight)
        setColor(guide.textColor)
        printg(guideRestart.text, guideRestart.textX, guideRestart.textY)
        setColor(guide.areaColor)
        drawRectangle("fill", guideRestart.areaX, guideRestart.areaY, guideRestart.areaWidth, guideRestart.areaHeight)
        setColor(guide.triangleColor)
        polygon("fill",
            guideRestart.triangleX, guideRestart.triangleY1,
            guideRestart.triangleX - guideRestart.triangleWidth / 2, guideRestart.triangleY2,
            guideRestart.triangleX + guideRestart.triangleWidth / 2, guideRestart.triangleY2
        )
        setLineWidth(3)
        setColor(guide.triangleColor)
        drawRectangle("line", 0, guideRestart.rectY, width, guideRestart.rectHeight)
        drawRectangle("line", guideRestart.areaX, guideRestart.areaY, guideRestart.areaWidth, guideRestart.areaHeight)
    elseif guide.step == 9 then
        -- 对手生命值
        setColor(guide.textBackgroundColor)
        drawRectangle("fill", 0, guideLifeOpponent.rectY, width, guideLifeOpponent.rectHeight)
        setColor(guide.textColor)
        printg(guideLifeOpponent.text, guideLifeOpponent.textX, guideLifeOpponent.textY)
        setColor(guide.areaColor)
        drawRectangle("fill", guideLifeOpponent.areaX, guideLifeOpponent.areaY, guideLifeOpponent.areaWidth, guideLifeOpponent.areaHeight)
        setColor(guide.triangleColor)
        polygon("fill",
            guideLifeOpponent.triangleX, guideLifeOpponent.triangleY1,
            guideLifeOpponent.triangleX - guideLifeOpponent.triangleWidth / 2, guideLifeOpponent.triangleY2,
            guideLifeOpponent.triangleX + guideLifeOpponent.triangleWidth / 2, guideLifeOpponent.triangleY2
        )
        setLineWidth(3)
        setColor(guide.triangleColor)
        drawRectangle("line", 0, guideLifeOpponent.rectY, width, guideLifeOpponent.rectHeight)
        drawRectangle("line", guideLifeOpponent.areaX, guideLifeOpponent.areaY, guideLifeOpponent.areaWidth, guideLifeOpponent.areaHeight)
    elseif guide.step == 10 then
        -- 天赋栏
        setColor(guide.textBackgroundColor)
        drawRectangle("fill", 0, guideGift.rectY, width, guideGift.rectHeight)
        setColor(guide.textColor)
        printg(guideGift.text, guideGift.textX, guideGift.textY)
        setColor(guide.areaColor)
        drawRectangle("fill", guideGift.areaX, guideGift.areaY, guideGift.areaWidth, guideGift.areaHeight)
        setColor(guide.triangleColor)
        polygon("fill",
            guideGift.triangleX, guideGift.triangleY1,
            guideGift.triangleX - guideGift.triangleWidth / 2, guideGift.triangleY2,
            guideGift.triangleX + guideGift.triangleWidth / 2, guideGift.triangleY2
        )
        setLineWidth(3)
        setColor(guide.triangleColor)
        drawRectangle("line", 0, guideGift.rectY, width, guideGift.rectHeight)
        drawRectangle("line", guideGift.areaX, guideGift.areaY, guideGift.areaWidth, guideGift.areaHeight)
    elseif guide.step == 11 then
        -- 更多帮助
        setColor(guide.textBackgroundColor)
        drawRectangle("fill", 0, guideMore.rectY, width, guideMore.rectHeight)
        setColor(guide.textColor)
        printg(guideMore.text, guideMore.textX, guideMore.textY)
        setColor(guide.areaColor)
        drawRectangle("fill", guideMore.areaX, guideMore.areaY, guideMore.areaWidth, guideMore.areaHeight)
        setColor(guide.triangleColor)
        polygon("fill",
            guideMore.triangleX, guideMore.triangleY1,
            guideMore.triangleX - guideMore.triangleWidth / 2, guideMore.triangleY2,
            guideMore.triangleX + guideMore.triangleWidth / 2, guideMore.triangleY2
        )
        setLineWidth(3)
        setColor(guide.triangleColor)
        drawRectangle("line", 0, guideMore.rectY, width, guideMore.rectHeight)
        drawRectangle("line", guideMore.areaX, guideMore.areaY, guideMore.areaWidth, guideMore.areaHeight)
    elseif guide.step == 12 then
        -- 努力获取更高分
        setColor(guide.textBackgroundColor)
        drawRectangle("fill", 0, guideEnd.rectY, width, guideEnd.rectHeight)
        setColor(guide.textColor)
        printg(guideEnd.text, guideEnd.textX, guideEnd.textY)
        setLineWidth(3)
        setColor(guide.triangleColor)
        drawRectangle("line", 0, guideEnd.rectY, width, guideEnd.rectHeight)

        guideFinished = true
    end
end

local function addStep()
    guide.step = guide.step + 1
end

local function inAreaSkip(x)
    if guide.step > 1 then return false end
    return x > midLine.x
end

local function isHovered(x)
    if guide.step > 1 then return end
    if inAreaSkip(x) then
        guideNewPlayer.buttonColor = guideNewPlayer.buttonColorNormal
        guideNewPlayer.areaColor = guideNewPlayer.areaColorNormal
        guideSkip.buttonColor = guideSkip.buttonColorHovered
        guideSkip.areaColor = guideSkip.areaColorHovered
    else
        guideNewPlayer.buttonColor = guideNewPlayer.buttonColorHovered
        guideNewPlayer.areaColor = guideNewPlayer.areaColorHovered
        guideSkip.buttonColor = guideSkip.buttonColorNormal
        guideSkip.areaColor = guideSkip.areaColorNormal
    end
end

return {
    init = init,
    drawGuide = drawGuide,
    addStep = addStep,
    getGuideFinished = function() return guideFinished end,
    inAreaSkip = inAreaSkip,
    isHovered = isHovered
}